<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<!--标准mui.css-->
		<link rel="stylesheet" href="../css/mui.min.css">
		<!--App自定义的css-->
		<style type="text/css">
			.mui-fullscreen{
				position: fixed;
				z-index: 20;
				background-color: #000;
			}
			p img{
				max-width: 100%;
				height: auto;
			}
		</style>
		
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">image viewer（图片预览）</h1>
		</header>
		<div class="mui-content">
			<div class="mui-content-padded">
				<p>这是图片放大预览示例，点击如下图片体验全屏预览功能</p>
				<p><img src="../images/cbd.jpg" class="mui-action-preview"/></p>
				<p>图片全屏后，左右滑动可查看本页其它图片，点击会关闭预览</p>
				<p><img src="../images/muwu.jpg" alt="" class="mui-action-preview" /></p>
				<p>第三张图片，纯粹为了占位： </p>
				<p><img src="../images/shuijiao.jpg" alt="" class="mui-action-preview"/></p>
			</div>
		</div>
	</body>
	<script src="../js/mui.min.js"></script>
	<script>
		mui.init();
		mui.ready(function () {
			var imgs = document.querySelectorAll("img.mui-action-preview");
			imgs = mui.slice.call(imgs);
			var slider = null;
			if(imgs&&imgs.length>0){
				slider = document.createElement("div");
				slider.setAttribute("id","__mui-imageview__");
				slider.classList.add("mui-slider");
				slider.classList.add("mui-fullscreen");
				slider.style.display = "none";
				slider.addEventListener("tap",function () {
					slider.style.display = "none";
				});
				slider.addEventListener("touchmove",function (event) {
					event.preventDefault();
				})
				
				var slider_group = document.createElement("div");
				slider_group.setAttribute("id","__mui-imageview__group");
				slider_group.classList.add("mui-slider-group");
				
				imgs.forEach(function (value,index,array) {
					//给图片添加点击事件，触发预览显示；
					value.addEventListener('tap',function () {
						slider.style.display = "block";
						_slider.refresh();
						_slider.gotoItem(index,0);
					})
					
					var item = document.createElement("div");
					item.classList.add("mui-slider-item");
					var a = document.createElement("a");
					// a.setAttribute("href","#");
					var img = document.createElement("img");
					img.setAttribute("src",value.src);
					a.appendChild(img)
					item.appendChild(a);
					slider_group.appendChild(item);
				});
				
				slider.appendChild(slider_group);
				document.body.appendChild(slider);
				var _slider = mui(slider).slider();
			}
			
			var oldback = mui.back;
			mui.back = function () {
				if(slider&&slider.style.display=="block"){
					slider.style.display = "none";
				}else{
					oldback();
				}
			}
			
		});
		
		
		
	</script>

</html>